package com.woke.bean;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.woke.dao.WokeDao;
import com.sun.jmx.snmp.Timestamp;
import com.woke.dao.User;

public class UserBean {

	public static User login(String username, String password,String role) {
		String sql = "select * from user where username='" + username + "' and password = '" + password + "'and role='"+role+"'";
		List<User> list = User.getData(sql);
		if (list.size() > 0) {
			return list.get(0);
		} else {
			return null;
		}
	}

	public static List getUserList() {
		String sql = "select * from user order by id desc";
		return User.getData(sql);
	}

	public static List getUserList1(String username) {
		String sql = "select * from user where username='"+username+"'";
		return User.getData(sql);
	}
	

	
	public static void adduser(String username, String password,String sex,String tel,String email, String role) {
		String sql = "insert into user(username,password,sex,tel,email,role) values('" + username + "','" + password + "','" + sex+ "','" + tel + "','" + email + "','" + role+ "')";
		WokeDao.updateMySqlData(sql);
	}

	

	
	public static void deleteuser(String id) {
		String sql = "delete from user where id=" + id;
		WokeDao.updateMySqlData(sql);
	}

	
	public static void updateuser(String id,String username, String sex,String email,String tel) {
		String sql = "update user set username='" + username + "',sex='" + sex
				+ "',email='"+email+"',tel='"+tel+"' where id=" + id;
		WokeDao.updateMySqlData(sql);
	}
	
	public static void updatepassword(String id, String password) {
		String sql = "update user set password='" + password + "' where id=" + id;
		WokeDao.updateMySqlData(sql);
	}
	
	public static void updaterole(String id, String role) {
		String sql = "update user set role='" + role + "' where id=" + id;
		WokeDao.updateMySqlData(sql);
	}

	public static List selectUser(String username,String id) {
		String sql = "select * from user where 1=1";
		if (!username.equals("")) {
			sql += " and username like '%" + username + "%'";
		}
		if (!id.equals("")) {
			sql += " and id like '%" + id + "%'";
		}
		return User.getData(sql);
	}

	

}
